//
//  PBFlatButton.m
//  FlatUIlikeiOS7
//
//  Created by Piotr Bernad on 11.06.2013.
//  Copyright (c) 2013 Piotr Bernad. All rights reserved.
//

#import "PBFlatButton.h"


@implementation PBFlatButton

@synthesize isFirstTouch,hasFooter,listLength;

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self appearanceButton];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self appearanceButton];
    }
    return self;
}

- (void)appearanceButton {
    _backgroundColor = [UIColor clearColor];
    _mainColor = [[PBFlatSettings sharedInstance] mainColor];
    
    [self setBackgroundColor:_backgroundColor];
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.titleLabel setFont:[[PBFlatSettings sharedInstance] font]];
}

- (void)setHighlighted:(BOOL)highlighted {
    if (self.highlighted != highlighted) {
        [super setHighlighted:highlighted];
        [self setNeedsDisplay];
    }
}

- (void)setSelected:(BOOL)selected {
    if (self.selected != selected) {
        [super setSelected:selected];
        [self setNeedsDisplay];
    }
}

- (void)drawRect:(CGRect)rect {
    UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:0];
    if (self.highlighted) {
        if (self.highlightColor == nil) {
            [self.backgroundColor setFill];
        }
        else {
            [self.highlightColor setFill];
        }
    }
    else if (self.selected) {
        if (self.selectedColor == nil) {
            [self.backgroundColor setFill];
        }
        else {
            [self.selectedColor setFill];
        }
    }
    else {
         [self.backgroundColor setFill];
    }
  
    [roundedRectanglePath fill];
    [super drawRect:rect];
//    [_mainColor setStroke];
//    roundedRectanglePath.lineWidth = 2;
//    [roundedRectanglePath stroke];
}

@end
